package mostFrequentEven;

import java.util.HashMap;
import java.util.Map;

public class Solution {
    public int mostFrequentEven(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        int max = 0;
        int ans = -1;
        for (int num: nums) {
            if(num%2==0) {
                int v = map.getOrDefault(num,0)+1;
                if(max<v) {
                    ans = num;
                    max = v;
                }
                map.put(num,v);
            }
        }
        return ans;
    }
}
